package com.younion.action.consumer.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.younion.action.consumer.AbstractRequestConsumer;
import com.younion.action.interactive.mobile.ApiConstant;
import com.younion.action.interactive.mobile.ResultObject;
import com.younion.business.IMemberCardCostCountService;
import com.younion.model.MemberCardCostCountResult;
import com.younion.util.HttpRequestUtils;
import com.younion.util.JsonUtils;
import com.younion.vo.MemberCardCostCountVO;

public class MemberCardCostCountGetConsumer extends AbstractRequestConsumer {
	
	private IMemberCardCostCountService memberCardCostCountService = null;

	@Override
	public String execute(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		return getMemberCardCostCount(request, response);
	}

	public String getMemberCardCostCount(HttpServletRequest request,
			HttpServletResponse response) {
		List<MemberCardCostCountResult> memberCardCostCountResultList = new ArrayList<MemberCardCostCountResult>();
		String card_id = request.getParameter("card_id");
		List<MemberCardCostCountVO> memberCardCostCountVOList = new ArrayList<MemberCardCostCountVO>();
		ResultObject resultObject = new ResultObject();
		Map paramMap = new HashMap();
		paramMap.put("memberCardId", card_id);
		try {
			memberCardCostCountVOList = (List<MemberCardCostCountVO>) memberCardCostCountService.getByMap(paramMap);
			if(memberCardCostCountVOList!=null&&memberCardCostCountVOList.size()>0){
				for(MemberCardCostCountVO memberCardCostCountVO:memberCardCostCountVOList){
					MemberCardCostCountResult memberCardCostCountResult = new MemberCardCostCountResult();
					memberCardCostCountResult.setId(memberCardCostCountVO.getId().toString());
					memberCardCostCountResult.setCount(memberCardCostCountVO.getCount().toString());
					memberCardCostCountResult.setProductName(memberCardCostCountVO.getProduct().getName());
					memberCardCostCountResultList.add(memberCardCostCountResult);
				}
			}
			resultObject.setStatus(ApiConstant.SUCCESS_STATUS);

		} catch (Exception e) {
			resultObject.setStatus(ApiConstant.FALSE_STATUS);
			resultObject.setMsg(ApiConstant.PUBLIC_EXCEPTION);
			e.printStackTrace();
		}
		resultObject.setResult(memberCardCostCountResultList);
		HttpRequestUtils.printContent(JsonUtils.parseObj2Json(resultObject),
				response);
		return null;
	}

	public void setMemberCardCostCountService(
			IMemberCardCostCountService memberCardCostCountService) {
		this.memberCardCostCountService = memberCardCostCountService;
	}

}
